package org.jeecg.modules.basesource.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import org.jeecg.modules.basesource.constant.FpzlDmEnum;
import org.jeecg.modules.basesource.entity.FpSyncRecord;
import org.jeecg.modules.basesource.mapper.FpSyncRecordMapper;
import org.jeecg.modules.basesource.service.IFpSyncRecordService;
import org.jeecg.modules.fk.entity.DjOrg;
import org.jeecg.modules.fk.service.IDjOrgService;
import org.jeecg.modules.qyxx.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 发票同步日志
 * @Author: jeecg-boot
 * @Date: 2022-03-02
 * @Version: V1.0
 */
@Service
public class FpSyncRecordServiceImpl extends ServiceImpl<FpSyncRecordMapper, FpSyncRecord> implements IFpSyncRecordService {
    @Autowired
    private IDjOrgService djOrgService;

    @Override
    public void init(String fplxDm, List<DjOrg> orgs, Integer cjfs, List<Date> dates) {
        FpzlDmEnum[] values = FpzlDmEnum.values();
        DateUtils utils = DateUtils.getInstance();
        Date now = new Date();
        List<FpSyncRecord> list = new ArrayList<>();
        for (DjOrg org : orgs) {
            for (Date date : dates) {
                for (FpzlDmEnum value : values) {
                    FpSyncRecord record = new FpSyncRecord();
                    record.setFpzlDm(value.getValue());
                    record.setDjxh(org.getDjxh());
                    record.setNsrsbh(org.getShxydm());
                    record.setStatus("001");
                    record.setCjrq(date);
                    record.setFplxDm(fplxDm);
                    record.setCreateTime(now);
                    record.setUpdateTime(now);
                    record.setCjfs(cjfs);
                    String kpyf = utils.getMonthToStr(date);
                    record.setKpyf(kpyf);
                    list.add(record);
                }
            }
        }
        saveBatch(list,list.size());
    }
}
